package com.cgydu.dao.impl;

import com.cgydu.dao.TypeDao;
import com.cgydu.entity.Type;
import com.cgydu.utils.ConnectionUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * projectName: day25_store
 * author: CGY
 * time: 2020/8/27 16:54
 * description:
 */
public class TypeDaoImpl implements TypeDao {
    @Override
    public List<Type> queryTypes(int num) throws SQLException {
        String sql = "select t_id tid,t_name tname,t_info tinfo from type limit ?;";
        QueryRunner queryRunner = new QueryRunner(ConnectionUtils.getDataSource());
        List<Type> types = queryRunner.query(sql,new BeanListHandler<Type>(Type.class),num);

        return types;
    }
}
